package net.thelostlands.plugins.TheLostKindness;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy;
import net.thelostlands.plugins.TheLostKindness.CommandHandler.CommandHandler;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

/**
 *
 * @author fabio
 */
//ciao
public class Main extends JavaPlugin{
    
    Vault vault;
    
    public static final Logger log = Logger.getLogger("Minecraft");
    String dataDirectory;
    String mainDirectory;
    Economy economy;
    CommandHandler cmdExec;
    public static HashMap<String, KindPlayer> players = new HashMap<String, KindPlayer>();
    @Override
    public void onDisable() {
        log.info("Plugin 'TheLostKindness' disattivo");
    }

    @Override
    public void onEnable() {
        log.info("Plugin 'TheLostKindness' Attivo");
        //creo la cartella del plugin, se non esiste
        File dir = new File(dataDirectory);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        //carico i plugin necessari
        vault = (Vault) this.getServer().getPluginManager().getPlugin("Vault");
        if(vault == null) {
            log.severe("[TheLostKindness] Non trovo Vault. Esco.");
            return;
        }
        Collection<RegisteredServiceProvider<Economy>> allEco = this.getServer().getServicesManager().getRegistrations(net.milkbowl.vault.economy.Economy.class);
        for(RegisteredServiceProvider<Economy> e : allEco){
            Economy eco = e.getProvider();
            if(eco.isEnabled()){
                economy = eco;                
            }
        }
        if (economy == null) {
            log.severe("[TheLostKindness] Non ho trovato ho trovato metodi di pagamento. Esco.");
            return;
        }
        log.info(String.format("[%s] Uso %s", getDescription().getName(), economy.getName()));
        //dico di registrare il comando kind
        cmdExec = new CommandHandler(this);
        getCommand("kind").setExecutor(cmdExec);
        File configFile = new File(mainDirectory + File.separator + "config.yml");

        
        //carico i file di configurazione ...
        //carico i dati salvati...
    }


}
